package com.woorigil.android.koreaflower.domain.app;


import org.json.JSONObject;

import com.woorigil.android.koreaflower.ApiUrl;
import com.woorigil.android.koreaflower.AppContext;
import com.woorigil.android.koreaflower.domain.BaseDao;
import com.woorigil.android.koreaflower.support.HttpUtils;

public class AppInfomationDao extends BaseDao {
	
	public AppInformation initializeApp() {
		try {
			String result = HttpUtils.execute(ApiUrl.informationUrl + "?" + AppContext.getSid(getApplicationContext()), 1500);
			JSONObject jSONObject = new JSONObject(result);
			
			AppInformation appInformation = new AppInformation();
			appInformation.setAppVersion(jSONObject.getString("appVersion"));
			appInformation.setDealTotalCount(jSONObject.getInt("productTotalCount"));
			appInformation.setDealListLimitCount(jSONObject.getInt("productListLimitCount"));
			appInformation.setLastUpdatedTime(jSONObject.getLong("productUpdatedTime"));
			appInformation.setCategoryJson(jSONObject.getJSONArray("categories").toString());
			return appInformation;
		} catch (Exception e) {
			throw new IllegalStateException(e.getMessage(), e);
		}
	}
}
